const {
    TripleEncrypt,
    Mysql
} = require('../tools');
module.exports = async ctx => {
    let {
        uid,
        openId,
        vid
    } = ctx.query;
    if (!uid || !openId || !vid) {
        ctx.state.data = {
            code: '002',
            msg: '参数缺失'
        }
    } else {
        try {
            let sql = `SELECT * FROM buyVideo WHERE openId='${openId}' AND vid= ${Number(vid)}`;
            let res = await Mysql(sql);
            if (res.length) {
                ctx.state.data = {
                    code: '001',
                    data: TripleEncrypt(JSON.stringify({
                        vid,
                        status: 1
                    }))
                }
            } else {
                ctx.state.data = {
                    code: '001',
                    data: TripleEncrypt(JSON.stringify({
                        vid,
                        status: 0
                    }))
                }
            }
        } catch (error) {
            ctx.state.data = {
                code: '002',
                msg: '内部错误'
            }
        }
    }
}